﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Hypermarket_Serial_Port
{
    class LogOutManager : CashierRegisterTaskManager
    {

        #region Constructor
        public LogOutManager()
        {
        }
        #endregion


        #region Operation LogOut
        //received a list of string from controller
        public override List<string> TaskOperation(List<string> receivedInfoList, Dictionary<string, CashierRegister> cashiersDict)
        {

            try
            {
                SerialPortLog.Log("Logout Start");
                //string machineID = (int.Parse(s_receivedInform.Substring(1, 1))).ToString().PadLeft(4, '0');
                string machineID = receivedInfoList[Constant.ZERO];
                string type = receivedInfoList[Constant.ONE];
                SerialPortLog.LogOperation("Logout: " + machineID);
                //string endCheckByte = s_receivedInform.Substring(11, 1);
                if (cashiersDict.Remove(machineID))
                {
                     List<string> output = new List<string>();
                     output.Add(machineID);
                     output.Add(type);
                     output.Add(Constant.SUCCESS);
                     SerialPortLog.LogOperation("Logout Successfully");
                     SerialPortLog.Log("Logout Successfully");
                     return output;
                 }
                 else
                 {
                     List<string> output = new List<string>();
                     output.Add(machineID);
                     output.Add(type);
                     output.Add(Constant.FAIL);
                     SerialPortLog.LogOperation("Logout Fail");
                     SerialPortLog.Log("Logout Fail");
                     return output;
                 }
            }
            catch
            {
                SerialPortLog.LogOperation("Logout Error");
                SerialPortLog.Log("Logout Error");
                throw;
                //List<string> tempStr = new List<string>();
                //tempStr.Add(Constant.PROGRAM_ERROR);
                //return tempStr;

            }
        }
        #endregion 
    }
}
